package zuoye.shixun;
class Rabbit implements Runnable {			
	@Override
	public void run() {
		Tortoise runTortoise = new Tortoise();
		Thread tortoise = new Thread(runTortoise);
		tortoise.start();						
		for (int i = 1; i <= 10; i++) {			
			try {
				Thread.sleep(100);			
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println("兔子跑了" + i * 10 + "米");	
			if (i == 8) {
				System.out.println("兔子在睡觉");		
				try {
					tortoise.join();						
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
		System.out.println( "兔子到达终点");				
	}
}
class Tortoise implements Runnable {					
	@Override
	public void run() {
		for (int i = 1; i <= 10; i++) {
			try {
				Thread.sleep(500);				
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println("乌龟跑了" + i * 10 + "米");
		}
		System.out.println("乌龟到达终点");
	}
}
public class Race {
	public static void main(String[] args) {
		Runnable runRabbit = new Rabbit();	
		Thread rabbit = new Thread(runRabbit);
		rabbit.start();									
	}
}